package com.proyecto.track.dao;

import java.util.ArrayList;

import org.hibernate.SessionFactory;

import com.proyecto.track.bo.Rol;

public class RolDAOImp implements RolDAO{

	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public Long createRol(Rol rol) {
		sessionFactory.getCurrentSession().save(rol);
		return rol.getId();
	}

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<Rol> searchRols() {
		return  ( ArrayList<Rol>) sessionFactory.getCurrentSession().createQuery("from Rol").list();
	}

	@Override
	public Rol search(Long id) {
		return (Rol) sessionFactory.getCurrentSession().get(Rol.class, id);
	}

}
